package com.eascs.p2p.admin.service.impl;

import java.util.List;

import javax.inject.Inject;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.p2p.admin.manager.IBannerManager;
import com.eascs.p2p.common.entity.BannerSetEntity;
import com.eascs.p2p.common.service.IBannerService;
import com.eascs.p2p.common.vo.BannerVO;
import com.eascs.p2p.common.vo.ModelResult;

@Service
public class BannerServiceImpl implements IBannerService {
	@Inject
	IBannerManager bannerManager;

	@Override
	public ModelResult<PageResult<Object[]>> findPageBannerSetEntity(BannerVO vo) {
		ModelResult<PageResult<Object[]>> result = new ModelResult<PageResult<Object[]>>();
		try {
			result.setModel(bannerManager.findPageBannerSetEntity(vo));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("banner图分页查询：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<String> addBannerSetEntity(BannerSetEntity bannerSetEntity) {
		ModelResult<String> result = new ModelResult<String>();
		try {
			result.setModel(bannerManager.addBannerSetEntity(bannerSetEntity));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("banner图的添加：", e.getMessage());
		}
		return result;   
	}

	@Override
	public ModelResult<Boolean> updateBannerSetEntity(BannerSetEntity bannerSetEntity) {
		
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		BannerSetEntity	banner=bannerManager.findBannerSetEntityDetail(bannerSetEntity.getId());
		try {
			banner.setName(bannerSetEntity.getName());
			banner.setCode(bannerSetEntity.getCode());
			banner.setImageUrl(bannerSetEntity.getImageUrl());
			banner.setUrl(bannerSetEntity.getUrl());
			banner.setBannerOrder(bannerSetEntity.getBannerOrder());
			banner.setIsLinkEnabled(bannerSetEntity.getIsLinkEnabled());
			banner.setTarget(bannerSetEntity.getTarget());
			result.setModel(bannerManager.updateBannerSetEntity(banner));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("banner图的更新：", e.getMessage());
		}
		return result;   
	}

	@Override
	public ModelResult<BannerSetEntity> findBannerSetEntityDetail(String id) {
		
		ModelResult<BannerSetEntity> result = new ModelResult<BannerSetEntity>();
		try {
			result.setModel(bannerManager.findBannerSetEntityDetail(id));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("banner图的详情查询：", e.getMessage());
		}
		return result;
	}

	@Override
	public ModelResult<Boolean> updateBannerStatus(String id, int isDisplay) {
		ModelResult<Boolean> result = new ModelResult<Boolean>();
		try {
			result.setModel(bannerManager.updateBannerStatus(id, isDisplay));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("banner图前台是否显示：", e.getMessage());
		}
		return result;   
	}

	@Override
	public ModelResult<List<BannerSetEntity>> getBannerSetEntity(String code) {

		ModelResult<List<BannerSetEntity>> result = new ModelResult<List<BannerSetEntity>>();
		try {
			result.setModel(bannerManager.getBannerSetEntity(code));
		} catch (Exception e) {
			e.printStackTrace();
			result.withError("banner图前台显示：", e.getMessage());
		}
		return result;   
	}
	
	 
	
}
